<?php

namespace co2_OS\apps\sdk\dev\v0_0_0\app;

use co2_OS as kernel;
use co2\dev\v0_0_0 as api;

class command

{
  protected
    $default_editor='gedit';
    
  public function __construct
  (
    $app,
    $version,
    $channel,
    $command,
    \stdClass $options=null
  )
  {
    $base=kernel\sysvar::get('apps')."/$app/$channel/$version";
    
    if(!is_dir($base))
    throw new api\Exception('App not found');
    
    $f="$base/$command.php";
    
    if(file_exists($f))
    throw new api\Exception('Command already exists');
    
    $Version=preg_replace('/\./','_',$version);
    
    $code=<<<PHP
<?php

/*
 *  @file-type        app command
 *  @app              $app
 *  @version          $version
 *  @channel          $channel
 *  @command          $command
 */

namespace co2_OS\\apps\\$app\\$channel\\v$Version;

use co2_OS as kernel;
use co2\\dev\\v0_0_0 as api;

class $command

{
  public function __construct
  (

  )
  {

  }
  
  public function __invoke
  (

  )
  {

  }
  
  public function __toString
  (

  )
  {
    return 'co2 is a cool =^-^=';
  }
}
PHP;

    $file=new api\File($f);
    
    $file->put($code);
    
    `$this->default_editor $base/$command.php < \`tty\` > \`tty\``;
  }
}
